package models

import (
	"database/sql/driver"
	"gorm.io/gorm"
	"strings"
	"time"
)

type Strs []string

func (m *Strs) Scan(val interface{}) error {
	s := val.([]uint8)
	ss := strings.Split(string(s), "|")
	*m = ss
	return nil
}
func (m Strs) Value() (driver.Value, error) {
	str := strings.Join(m, "|")
	return str, nil
}

// 创建、更新时间
type Timestamps struct {
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

// 软删除
type SoftDeletes struct {
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

type BaseShare struct {
	PageId       uint         `json:"pageId" gorm:"primaryKey"`
	PageName     string       `json:"pageName" gorm:"not null;comment:页面名称"`
	Remark       string       `json:"remark" gorm:"not null;comment:副标题"`
	CoverUrl     string       `json:"coverUrl" gorm:"not null;comment:封面"`
	Status       int          `json:"status" gorm:"not null default: 0; comment:状态 0-下架中 1-上架中"`
	Spacial      string       `json:"spacial" gorm:"not null;comment: 专题"`
	ArtType      int          `json:"artType" gorm:"not null; comment: 1-音乐 2-技术 3-文化"`
	Tags         Strs         `json:"tags" gorm:"type:longtext; not null; comment: 标签"`
	Author       string       `json:"author" gorm:"not null; comment:作者"`
	ContentShare ContentShare `json:"contentShare"`
	Timestamps
	SoftDeletes
}

type ContentShare struct {
	ContentId       uint   `json:"contentId" gorm:"primaryKey"`
	Content         string `json:"content" gorm:"not null;comment: md内容"`
	VideoUrl        string `json:"videoUrl" gorm:"not null;comment:视频地址"`
	BaseSharePageId uint   `json:"baseSharePageId"`
	Timestamps
	SoftDeletes
}
